package com.guoamo.mapdemo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemoA {


    public static void main(String[] args) {


        //1 初始化map对象
        Map<String, Integer> map1 = new HashMap<>();

        //map集合初始化完后默认是没有值的 null
        Integer i1 = map1.put("one", 1);
        Integer i2 = map1.put("one", 10);
        map1.put("two", 2);
        map1.put("three", 3);
        map1.put("four", 3);
        map1.put("five", 3);


        System.out.println(map1.containsKey("two"));
        System.out.println(map1.containsKey("twoo"));

        System.out.println(map1.containsValue(3));
        System.out.println(map1.containsValue(30));


        System.out.println(map1.isEmpty());


        System.out.println(map1.size());


        //获取map中所有的键的集合
        Set<String> keys = map1.keySet();


        for (String key : keys) {

            Integer value = map1.get(key);
            System.out.println(key + ":" + value);
        }


//        Collection<Integer> values = map1.values();
//        System.out.println(keys.getClass().getName());
//        System.out.println("--------------------");
//        System.out.println(values.getClass().getName());
//        System.out.println("--------------------");


        //EntrySet <Node>
        Set<Map.Entry<String, Integer>> entries = map1.entrySet();

//        System.out.println(entries.getClass().getName());

        for (Map.Entry<String, Integer> entry : entries) {
//            System.out.println(entry.getClass().getName() + ": " + entry.getKey());
//            System.out.println(entry.getKey() + " : " + entry.getValue());
        }

//        map1.clear();

//        System.out.println(map1.isEmpty());
//        Integer i = map1.get("fiveeee");
//        System.out.println(i);


//        System.out.println(map1);

//        map1.put("three", 33);
//        Integer one = map1.remove("one");
//        {two=2, three=3}
//        System.out.println(one);
//        System.out.println(map1);
//        System.out.println(i1);
//        System.out.println(i2);
//        System.out.println(i);
//        System.out.println(map1);//{one=1, two=2, three=3}


        System.out.println(map1.get("six"));
    }
}
